<template>
    <div class="goods-list">
        <!-- 商品列表 -->
        <div class="goods_item" v-for="item in goodsList" :key="item.id" @click="goToInfo(item.id)">
            <div class="title">
                <img :src="item.img_url" alt="">
                <h3>{{item.title}}</h3>
            </div>
            <div class="info">
                <p class="price">
                    <span class="now">￥{{item.sell_price}}</span>
                    <span class="old">￥{{item.market_price}}</span>
                </p>
                <p class="num">
                    <span>热卖中</span>
                    <span>剩余{{item.stock_quantity}}件</span>
                </p>
            </div>
        </div> 
        <!-- 加载更多 -->
        <mt-button type="danger" size="large" @click="getMore">加载更多</mt-button>
    </div>
</template>

<script>
export default {
    data () {
        return {
            pageindex: 1, //默认商品页数
            goodsList: [
                {
                    id: 13,
                    title: 'Huawei/华为 畅享9 32G全面屏千元高清珍珠屏长续航正品智能游戏手机',
                    add_time: '2015-04-16T03:50:28.000Z',
                    zhaiyao: 'Huawei/华为 畅享9 32G全面屏千元高清珍珠屏长续航正品智能游戏手机',
                    click: 1,
                    img_url: '//img.alicdn.com/bao/uploaded/i7/TB1IpbZtNnaK1RjSZFt9c2C2VXa_032801.jpg',
                    sell_price: 2195,
                    market_price: 2499,
                    stock_quantity: 60            
                },
                {
                    id: 14,
                    title: 'Huawei/华为 畅享9 32G全面屏千元高清珍珠屏长续航正品智能游戏手机',
                    add_time: '2015-04-16T03:54:28.000Z',
                    zhaiyao: 'Huawei/华为 畅享9 32G全面屏千元高清珍珠屏长续航正品智能游戏手机',
                    click: 1,
                    img_url: '//img.alicdn.com/bao/uploaded/i6/TB1ZsyeikOWBuNjSsppZJtPgpXa_015433.jpg',
                    sell_price: 2195,
                    market_price: 2499,
                    stock_quantity: 50            
                },
                {
                    id: 15,
                    title: 'Huawei/华为 畅享9 32G全面屏千元高清珍珠屏长续航正品智能游戏手机',
                    add_time: '2015-04-16T03:55:28.000Z',
                    zhaiyao: 'Huawei/华为 畅享9 32G全面屏千元高清珍珠屏长续航正品智能游戏手机',
                    click: 1,
                    img_url: '//img.alicdn.com/bao/uploaded/i5/TB1rrySv4naK1RjSZFBLGoW7VXa_022422.jpg',
                    sell_price: 2195,
                    market_price: 2499,
                    stock_quantity: 160            
                },
                {
                    id: 16,
                    title: 'Huawei/华为 畅享9 32G全面屏千元高清珍珠屏长续航正品智能游戏手机',
                    add_time: '2015-04-16T03:56:28.000Z',
                    zhaiyao: 'Huawei/华为 畅享9 32G全面屏千元高清珍珠屏长续航正品智能游戏手机',
                    click: 1,
                    img_url: '//img.alicdn.com/bao/uploaded/i7/TB1IpbZtNnaK1RjSZFt9c2C2VXa_032801.jpg',
                    sell_price: 2195,
                    market_price: 2499,
                    stock_quantity: 620            
                },
                {
                    id: 17,
                    title: 'Huawei/华为 畅享9 32G全面屏千元高清珍珠屏长续航正品智能游戏手机',
                    add_time: '2015-04-16T03:57:28.000Z',
                    zhaiyao: 'Huawei/华为 畅享9 32G全面屏千元高清珍珠屏长续航正品智能游戏手机',
                    click: 1,
                    img_url: '//img.alicdn.com/bao/uploaded/i7/TB1IpbZtNnaK1RjSZFt9c2C2VXa_032801.jpg',
                    sell_price: 2195,
                    market_price: 2499,
                    stock_quantity: 260            
                },
                {
                    id: 18,
                    title: 'Huawei/华为 畅享9 32G全面屏千元高清珍珠屏长续航正品智能游戏手机',
                    add_time: '2015-04-16T03:58:28.000Z',
                    zhaiyao: 'Huawei/华为 畅享9 32G全面屏千元高清珍珠屏长续航正品智能游戏手机',
                    click: 1,
                    img_url: '//img.alicdn.com/bao/uploaded/i7/TB1IpbZtNnaK1RjSZFt9c2C2VXa_032801.jpg',
                    sell_price: 2195,
                    market_price: 2499,
                    stock_quantity: 99            
                },
                {
                    id: 19,
                    title: 'Huawei/华为 畅享9 32G全面屏千元高清珍珠屏长续航正品智能游戏手机',
                    add_time: '2015-04-16T03:59:28.000Z',
                    zhaiyao: 'Huawei/华为 畅享9 32G全面屏千元高清珍珠屏长续航正品智能游戏手机',
                    click: 1,
                    img_url: '//img.alicdn.com/bao/uploaded/i7/TB1IpbZtNnaK1RjSZFt9c2C2VXa_032801.jpg',
                    sell_price: 2195,
                    market_price: 2499,
                    stock_quantity: 60            
                },
                {
                    id: 20,
                    title: 'Huawei/华为 畅享9 32G全面屏千元高清珍珠屏长续航正品智能游戏手机',
                    add_time: '2015-04-16T04:50:28.000Z',
                    zhaiyao: 'Huawei/华为 畅享9 32G全面屏千元高清珍珠屏长续航正品智能游戏手机',
                    click: 1,
                    img_url: '//img.alicdn.com/bao/uploaded/i7/TB1IpbZtNnaK1RjSZFt9c2C2VXa_032801.jpg',
                    sell_price: 2195,
                    market_price: 2499,
                    stock_quantity: 60            
                },
                {
                    id: 21,
                    title: 'Huawei/华为 畅享9 32G全面屏千元高清珍珠屏长续航正品智能游戏手机',
                    add_time: '2015-04-16T05:50:28.000Z',
                    zhaiyao: 'Huawei/华为 畅享9 32G全面屏千元高清珍珠屏长续航正品智能游戏手机',
                    click: 1,
                    img_url: '//img.alicdn.com/bao/uploaded/i7/TB1IpbZtNnaK1RjSZFt9c2C2VXa_032801.jpg',
                    sell_price: 2195,
                    market_price: 2499,
                    stock_quantity: 60            
                },
                {
                    id: 22,
                    title: 'Huawei/华为 畅享9 32G全面屏千元高清珍珠屏长续航正品智能游戏手机',
                    add_time: '2015-04-16T06:50:28.000Z',
                    zhaiyao: 'Huawei/华为 畅享9 32G全面屏千元高清珍珠屏长续航正品智能游戏手机',
                    click: 1,
                    img_url: '//img.alicdn.com/bao/uploaded/i7/TB1IpbZtNnaK1RjSZFt9c2C2VXa_032801.jpg',
                    sell_price: 2195,
                    market_price: 2499,
                    stock_quantity: 60            
                }
            ],
            arrid: 50
        }
    },
    created () {
        this.getGoodsList()
    },
    methods: {
        getGoodsList() { //获取商品列表
            this.$http.get('api/getgoods?pageindex=' + this.pageindex).then( res => {
                if (res.body.status === 0) {
                    this.goodsList = this.goodsList.concat(res.body.message)
                }
            })
        },
        getMore() { //加载更多
            this.pageindex ++
            this.getGoodsList()

            this.arrid ++
            var arr = [{
                id: this.arrid,
                title: 'Huawei/华为 畅享9 64G全面屏千元高清珍珠屏长续航正品智能游戏手机',
                add_time: Date.now(),
                zhaiyao: 'Huawei/华为 畅享9 64G全面屏千元高清珍珠屏长续航正品智能游戏手机',
                click: 1,
                img_url: '//img.alicdn.com/bao/uploaded/i7/TB1IpbZtNnaK1RjSZFt9c2C2VXa_032801.jpg',
                sell_price: 2195,
                market_price: 2499,
                stock_quantity: 60            
            }]
            
            this.goodsList = this.goodsList.concat(arr)
        },
        goToInfo(id) {//进入商品详情页
            this.$router.push('/home/goodsinfo/'+ id)
        }
    }
}
</script>

<style lang="scss" scoped>
    .goods-list{
        padding: 5px;
        display: flex;
        flex-wrap: wrap;
        justify-content: space-between;
        .goods_item{
            width: 49%;
            border: 1px solid #ccc;
            box-shadow: 1px 1px 3px #ccc;
            margin-bottom: 5px;
            display: flex;
            flex-direction: column;
            justify-content: space-between;
            min-height: 260px;
            img{
                width: 100%;
            }
            h3{
                font-size: 12px;
                text-align: left;
                line-height: 15px;
                padding-left: 2px;
            }
            .info{
                background-color: #eee;
                p{
                    margin: 5px 0;
                }
                .price{
                    .now{
                        color: red;
                        font-weight: 700;
                        font-size: 13px;
                        margin-left: 8px;
                    }
                    .old{
                        text-decoration: line-through;
                        font-size: 12px;
                        margin-left: 8px;
                    }
                }
                .num{
                    display: flex;
                    justify-content: space-between;
                    font-size: 12px;
                    padding: 0 4px;
                }
            }
        }
    }
</style>

